package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 执行UPDATE语句
 */
public class JDBCDemo3 {
    public static void main(String[] args) {
        /*
            修改密码功能
         */
        try {
            Connection connection = DBUtil.getConnection();
            System.out.println("与数据库连接成功");
            Statement statement = connection.createStatement();
            /*
            UPDATE userinfo
            SET password = '6666666666'
            WHERE username = '赵六';
             */
            String sql = "UPDATE userinfo " +
                         "SET password = '123456' " +
                         "WHERE username = '王五'";
            int num = statement.executeUpdate(sql);
            if(num>0){
                System.out.println("修改成功");
            }else{
                System.out.println("修改失败");
            }

            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
